package java67_adv5;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

public class DateFormatTest {

	public static void main(String[] args) {
		String str = "yyyy年M月d日 h点m分";
		Date d = new Date();
		SimpleDateFormat df = new SimpleDateFormat(str);
		SimpleDateFormat df2 = new SimpleDateFormat();
		df2.applyPattern("yyyy-MM-dd");
		df2.setLenient(false);// 是否允许宽松格式
		String strdate = df.format(d);// Date->string
		System.out.println(strdate);
		Scanner in = new Scanner(System.in);
		System.out.println("请输入日期:");
		String s2 = in.next();
		Date d2;
		try {
			d2 = df2.parse(s2);// String ->Date
			System.out.println(d2);
		} catch (ParseException e) {

			e.printStackTrace();
		}

	}

}
